<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="sidebar.collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-sub-menu :index="item.index" :key="item.index" v-permiss="item.permiss">
                        <template #title>
                            <el-icon>
                                <component :is="item.icon"></component>
                            </el-icon>
                            <span>{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-sub-menu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                                v-permiss="item.permiss"
                            >
                                <template #title>{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-sub-menu>
                            <el-menu-item v-else :index="subItem.index" v-permiss="item.permiss">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index" v-permiss="item.permiss">
                        <el-icon>
                            <component :is="item.icon"></component>
                        </el-icon>
                        <template #title>{{ item.title }}</template>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useSidebarStore } from '../store/sidebar';
import { useRoute } from 'vue-router';

const items = [
    {
        icon:'Calendar',
        index: '/date',
        title: '会议日历',
        permiss: '1',
    },
    {
        icon:'Message',
        index: '/table',
        title: '议题一览表',
        permiss: '2',
    },
    {
        icon: 'DocumentCopy',
        index: '/notice',
        title: '通知界面',
        permiss: '3',
    },
    {
        icon: 'Warning',
        index: '/permission',
        title: '权限管理',
        permiss: '16',
    },
    {
        icon: 'UserFilled',
        index: '/hr',
        title: '人事管理',
        permiss: '16',
    },
        {
        icon: 'DocumentAdd',
        index: '/declare',
        title: '议题申报',
        permiss: '14',
    },
        {
        icon: 'Key',
        index: '/proposal',
        title: '会议筹备',
        permiss: '14',
    },
    //     {
    //     icon: 'Bell',
    //     index: '/notice',
    //     title: '通知界面',
    //     permiss: '14',
    // },
        {
        icon: 'FolderChecked',
        index: '/minutes',
        title: '填写纪要',
        permiss: '14',
    },
    {
        icon: 'FolderChecked',
        index: '/minute_see',
        title: '纪要一览',
        permiss: '14',
    },
    {
        icon: 'Edit',
        index: '3',
        title: '表单相关',
        permiss: '17',
        subs: [
            {
                index: '/form',
                title: '基本表单',
                permiss: '17',
            },
            {
                index: '/upload',
                title: '文件上传',
                permiss: '17',
            },
            {
                index: '4',
                title: '三级菜单',
                permiss: '17',
                subs: [
                    {
                        index: '/editor',
                        title: '富文本编辑器',
                        permiss: '17',
                    },
                    {
                        index: '/markdown',
                        title: 'markdown编辑器',
                        permiss: '17',
                    },
                ],
            },
        ],
    }
];

const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});

const sidebar = useSidebarStore();
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
